Imports System.Data.SqlClient
Imports System.Configuration
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Crystal.DatabaseManagement

Namespace BusinessLayer

    Public Class cImportInvestors

#Region "Declare"
      
        Public Event entInvRecordAdded()
        Private _DbFieldID As Integer
        Private _TemplateID As Integer
        Private _ESourceID As Integer
        Private _SourceTypeCode As String

#End Region

#Region "Properties"

        Public Property ESourceID() As Integer
            Get
                Return _ESourceID
            End Get
            Set(ByVal value As Integer)
                _ESourceID = value
            End Set
        End Property

        Public Property SourceTypeCode() As String
            Get
                Return _SourceTypeCode
            End Get
            Set(ByVal value As String)
                _SourceTypeCode = value
            End Set
        End Property

        Public Property TemplateID() As Integer
            Get
                Return _TemplateID
            End Get
            Set(ByVal value As Integer)
                _TemplateID = value
            End Set
        End Property

        Public Property DbFieldID() As Integer
            Get
                Return _DbFieldID
            End Get
            Set(ByVal value As Integer)
                _DbFieldID = value
            End Set
        End Property
#End Region

#Region "Methods"

        ''' <summary>
        ''' Created to Get the DisplayName and DbFieldId For Mapping Details
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>

        Public Function SelectDatabaseFields() As IDataReader
            Dim eReturnVal As ExecutionResult = Nothing
            Dim param(0) As SqlClient.SqlParameter
            param(0) = New SqlParameter("@SourceTypeCode", "INV")
            eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_InvestorDatabaseFields", CommandType.StoredProcedure, ReturnTypes.DataReader, param)
            Return CType(eReturnVal.ResultObject, IDataReader)
        End Function

        ''' <summary>
        ''' To Get Mapped FieldIds DBFieldID and Fieldname For Mapping Details
        ''' </summary>
        ''' <param name="pstrExcelColName"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>

        Public Function MapDatabaseColumn(ByVal pstrExcelColName As String) As ExecutionResult
            Dim eReturnVal As ExecutionResult = Nothing
            Const ARRAY_SIZE As Integer = 1
            'Try
            Dim param(ARRAY_SIZE) As SqlClient.SqlParameter
            param(0) = New SqlParameter("@FormatID", TemplateID)
            param(1) = New SqlParameter("@FileColumn", pstrExcelColName)
            eReturnVal = CoreFunctions.Execute(strConfiguration, "Cp_sp_INV_SEL_MappedInvestorDatabaseColumn", CommandType.StoredProcedure, ReturnTypes.DataSet, param)
            Return eReturnVal
            'Catch ex As Exception
            '    Throw ex
            'End Try
        End Function

        ''' <summary>
        '''  To Get Mapped FieldIds DBFieldID and Fieldname For Mapping Details
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>

        Public Function GetMappedColumns() As IDataReader
            Dim eReturnVal As ExecutionResult = Nothing
            Dim param(0) As SqlClient.SqlParameter
            param(0) = New SqlParameter("@TemplateID", TemplateID)
            eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_GetImportTemplateDetails", CommandType.StoredProcedure, ReturnTypes.DataReader, param)
            Return CType(eReturnVal.ResultObject, IDataReader)
        End Function

        ''' <summary>
        ''' To Check if any mandatory field left or not in Mapping Details
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>

        Public Function ChkImportInvestorIsIsmandatory() As ExecutionResult
            Dim eReturnVal As ExecutionResult = Nothing
            Const ARRAY_SIZE As Integer = 2
            'Try
            Dim param(ARRAY_SIZE) As SqlClient.SqlParameter
            param(0) = New SqlParameter("@ETemplateID", TemplateID)
            param(1) = New SqlParameter("@SourceTypeCode", SourceTypeCode)
            param(2) = New SqlParameter("@Name", SqlDbType.VarChar, 100)
            param(2).Direction = ParameterDirection.Output
            eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_CheckTemplateMandatoryFields", CommandType.StoredProcedure, ReturnTypes.NonQuery, param)
            Return eReturnVal
            'Catch ex As Exception
            '    Throw ex
            'End Try
        End Function

     

        ''' <summary>
        ''' To select the Source Names.
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>

        Public Function SelectSourceNames() As IDataReader
            Dim eReturnVal As ExecutionResult = Nothing
            Dim param(0) As SqlClient.SqlParameter
            param(0) = New SqlParameter("@SourceTypeCode", SourceTypeCode)
            eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_GetImportSources", CommandType.StoredProcedure, ReturnTypes.DataReader, param)
            Return CType(eReturnVal.ResultObject, IDataReader)
        End Function

        ''' <summary>
        ''' To select the import templates.
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>

        Public Function SelectImportTemplates() As IDataReader
            Dim eReturnVal As ExecutionResult = Nothing
            Dim param(0) As SqlClient.SqlParameter
            param(0) = New SqlParameter("@ESourceID", ESourceID)
            eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_GetImportTemplates", CommandType.StoredProcedure, ReturnTypes.DataReader, param)
            Return CType(eReturnVal.ResultObject, IDataReader)
        End Function


#End Region


#Region "Old"
        ''' <summary>
        ''' Function to Get All Investor
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared Function GetAllInvestor() As IDataReader
            Dim eReturnVal As ExecutionResult = Nothing
            eReturnVal = CoreFunctions.Execute(strConfiguration, "CP_spInvestorGetAll", CommandType.StoredProcedure, ReturnTypes.DataReader)
            Return CType(eReturnVal.ResultObject, IDataReader)
        End Function

        Public Shared Function SelectDatabaseField(ByVal sourceID As Integer) As IDataReader
            Dim eReturnVal As ExecutionResult = Nothing
            ' Try
            Dim param(0) As SqlClient.SqlParameter
            param(0) = New SqlParameter("@sourceID", sourceID)
            eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_InvestorDatabaseFields", CommandType.StoredProcedure, ReturnTypes.DataReader, param)
            Return CType(eReturnVal.ResultObject, IDataReader)
        End Function

#End Region
    End Class

End Namespace
